const cookieConfig = require('../../config/cookie');

module.exports = (io) => {
    // 广播cookie给所有连接的客户端
    const broadcastCookie = () => {
        console.log('广播cookie给所有客户端');
        io.emit('cookie:update', {
            status: 'success',
            data: {
                cookie: cookieConfig.cookie
            }
        });
    };

    // 当客户端请求cookie时
    const handleGetCookie = (socket) => {
        console.log('注册cookie:get事件处理程序');

        socket.on('cookie:get', () => {
            console.log('收到cookie:get请求，来自socket:', socket.id);

            socket.emit('cookie:update', {
                status: 'success',
                data: {
                    cookie: cookieConfig.cookie
                }
            });
        });
    };

    return {
        broadcastCookie,
        handleGetCookie
    };
}; 